﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
using INTEX.DataBase.Tools;
using ReflectionStudio.Core.Events;
namespace WPFExcelReport
{    
    public partial class JLTBB07Data : BaseFunction
    {
        ApplicationBase app
        {
            get
            {
                return ApplicationBase.Instance;
            }
        }
        INTEXDBC INTEXDBC
        {
            get
            {
                return app.INTEXDBC;
            }
        }
        /*public INTEXBL INTEXBL
        {
            get
            {
                return app.INTEXBL;
            }
        }

        SETINTEXDB INTEXDB = new SETINTEXDB();
         */
        public JLTBB07Data()
            : base()
        {
        }
         public JLTBB07Data(Dictionary<string, object> DicGlobalPara)
            : base(DicGlobalPara)
        {
        }

        public DataSet GetBB07(DataRow dwTABEL)
        {
            DataSet Result;
            DataSet Return = new DataSet();
            string TableName = "BB07";
            string CO = dwTABEL["CO"].ToString().Trim();
            string FROMDATE = dwTABEL["FROMDATE"].ToString().Trim();
            string ENDDATE = dwTABEL["ENDDATE"].ToString().Trim();
            try
            {
                orlReadCommand = INTEXDBC.OracleDB.CreateCommand();
                orlReadCommand.CommandText = " select A.BBBUCHDAT,trim(A.BBKART) as BBKART,TRIM(A.BBKFARBE) AS BBKFARBE, "
                    + " sum(decode(A.BBBS,'13',A.BBMTR,'73',-A.BBMTR)*0.1) AS MTR,B.BMKOLLINR, "
                    + " b.bmvwmpos,b.bmroda,TRIM(B.BMBEM) AS REMARK,B.BMFDZ,A.BBBAUMKRS,A.BBBAUMLFD, "
                    + " B.BMAUFKRS,B.BMAUFLFD,B.BMAUFPOS "
                    + " from babew a,BABST B "
                    + " where a.bbbs IN ('13','73') "
                    + " AND A.BBBUCHDAT >='" + FROMDATE + "' AND A.BBBUCHDAT <= '"+ENDDATE+"' "
                    + " AND A.BBKART LIKE '"+CO+"%' "
                    + " AND A.BBMANDANT = B.BMMANDANT AND A.BBBAUMKRS = B.BMBAUMKRS "
                    + " AND A.BBBAUMLFD = B.BMBAUMLFD "
                    + " group by A.BBBUCHDAT,A.BBKART,A.BBKFARBE,B.BMKOLLINR, "
                    + " b.bmvwmpos,b.bmroda,B.BMBEM,B.BMFDZ,A.BBBAUMKRS,A.BBBAUMLFD, "
                    + " B.BMAUFKRS,B.BMAUFLFD,B.BMAUFPOS "
                    + " order by 1,2,3 "                   
                    ;

                Result = INTEXDBC.Connect2Proxy(orlReadCommand);
                if (Result.Tables.Count > 0)
                {
                    Result.Tables[0].TableName = TableName;
                    byte[] b;
                    string value;
                    foreach (DataRow dw in Result.Tables[TableName].Rows)
                    {
                        b = Encoding.GetEncoding("ISO-8859-1").GetBytes(dw["REMARK"].ToString().Trim());
                        value = Encoding.GetEncoding("gb2312").GetString(b);
                        dw["REMARK"] = value;
                       
                    }
                }
                Return.Merge(Result);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return Return;
        }
        
        public DataSet BuildData(DataRow dwUI)
        {
            /*DataSet SResult = new DataSet();
            SETINTEXDB SReturn = new SETINTEXDB(); */
            DataSet setReturn = new DataSet();
            DataSet setResult = new DataSet();
            try
            {
                setResult = GetBB07(dwUI);
                setReturn.Merge(setResult);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return setReturn;
        }

    }
}